home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / windows.arc / WINDO.PAS < prev    next >
Pascal/Delphi Source File  |  1980-01-01  |  3KB  |  121 lines

  1. { Turbo Pascal removable window system }
  2. { For further documentation see PC Tech Journal, February 1985. }
  3. { Requirements: IBM PC or close compatible.   }
  4. { Screen must be in text mode, on page 1,     }
  5. { either mono or color card.                  }
  6. { Call INITWIN before calling MKWIN or RMWIN. }
  7. const maxwin = 5;  { maximum number of windows open at once }
  8.  
  9. type imagetype  = array [1..4096] of char; 
  10.      windimtype = record 
  11.                     x1,y1,x2,y2: integer 
  12.                   end; 
  13. var 
  14.   win: { Global variable package } 
  15.     record 
  16.       dim:    windimtype;  { Current window dimensions } 
  17.       depth:  integer;
  18.       stack:  array[1..maxwin] of 
  19.                 record 
  20.                   image: imagetype;  { Saved screen image } 
  21.                   dim:   windimtype; { Saved window dimensions } 
  22.                   x,y:   integer     { Saved cursor position } 
  23.                 end 
  24.     end; 
  25.  
  26.   crtmode:      byte      absolute $0040:$0049; 
  27.   crtwidth:     byte      absolute $0040:$004A; 
  28.   monobuffer:   imagetype absolute $B000:$0000; 
  29.   colorbuffer:  imagetype absolute $B800:$0000;
  30.  
  31. procedure initwin; 
  32.   { Records initial window dimensions } 
  33. begin 
  34.   with win.dim do 
  35.     begin x1:=1; y1:=1; x2:=crtwidth; y2:=25 end; 
  36.   win.depth:=0 
  37. end; 
  38.  
  39. procedure boxwin(x1,y1,x2,y2:integer); 
  40.   { Draws a box, fills it with blanks, and makes it the current }
  41.   { window.  Dimensions given are for the box; actual window is } 
  42.   { one unit smaller in each direction.                         } 
  43.   { This routine can be used separately from the rest of the    } 
  44.   { removable window package.                                   } 
  45. var x,y: integer; 
  46. begin 
  47.   window(1,1,80,25); 
  48.  
  49.   { Top } 
  50.   gotoxy(x1,y1); 
  51.   write(chr(213)); 
  52.   for x:=x1+1 to x2-1 do write(chr(205));
  53.   write(chr(184)); 
  54.  
  55.   { Sides } 
  56.   for y:=y1+1 to y2-1 do 
  57.     begin 
  58.       gotoxy(x1,y); 
  59.       write(chr(179), ' ':x2-x1-1, chr(179)) 
  60.     end; 
  61.  
  62.   { Bottom } 
  63.   gotoxy(x1,y2);
  64.   write(chr(212)); 
  65.   for x:=x1+1 to x2-1 do write(chr(205)); 
  66.   write(chr(190)); 
  67.  
  68.   { Make it the current window } 
  69.   window(x1+1,y1+1,x2-1,y2-1); 
  70.   gotoxy(1,1) 
  71. end; 
  72.  
  73. procedure mkwin(x1,y1,x2,y2:integer); 
  74.   { Create a removable window } 
  75.  
  76. begin 
  77.   { Increment stack pointer } 
  78.   with win do depth:=depth+1; 
  79.   if win.depth>maxwin then 
  80.     begin 
  81.       writeln(^G,' Windows nested too deep '); 
  82.       halt 
  83.     end; 
  84.  
  85.   { Save contents of screen } 
  86.   if crtmode = 7 then
  87.     win.stack[win.depth].image := monobuffer 
  88.   else 
  89.     win.stack[win.depth].image := colorbuffer; 
  90.  
  91.   win.stack[win.depth].dim := win.dim; 
  92.   win.stack[win.depth].x   := wherex; 
  93.   win.stack[win.depth].y   := wherey; 
  94.  
  95.   { Create the window } 
  96.   boxwin(x1,y1,x2,y2); 
  97.   win.dim.x1 := x1+1; 
  98.   win.dim.y1 := y1+1;    { Allow for margins }
  99.   win.dim.x2 := x2-1; 
  100.   win.dim.y2 := y2-1; 
  101.  
  102. end; 
  103.  
  104. procedure rmwin; 
  105.   { Remove the most recently created removable window } 
  106.   { Restore screen contents, window dimensions, and   } 
  107.   { position of cursor.  } 
  108. begin 
  109.   if crtmode = 7 then
  110.     monobuffer := win.stack[win.depth].image
  111.   else
  112.     colorbuffer := win.stack[win.depth].image;
  113.   with win do
  114.     begin
  115.       dim := stack[depth].dim;
  116.       window(dim.x1,dim.y1,dim.x2,dim.y2);
  117.       gotoxy(stack[depth].x,stack[depth].y);
  118.       depth := depth - 1
  119.     end
  120. end;
  121.